package com.example.yiqiuser.controller;


import com.example.yiqiuser.entity.TreeNode;
import com.example.yiqiuser.entity.User;
import com.example.yiqiuser.service.MenuService;
import com.example.yiqiuser.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import javax.ws.rs.GET;

/**
 * @ fileName:MenuController
 * @ description:
 * @ author:xjd
 * @ createTime:2023/3/27 11:43
 * @ version:1.0.0
 */
@RestController
@RequestMapping("menu") //父路径映射
public class MenuController extends BaseController {

    //依赖注入
    @Resource
    private MenuService menuService;


    /**
     * 查询树形数据
     * @return
     */
    @GetMapping("queryTreeData")
    public Result queryTreeData1(){
        return success(menuService.queryTreeData());
    }



    /**
     * 根据用户Id查权限
     * @return
     */
    @GetMapping("queryTreeDataByUserId")
    public Result queryTreeDataByUserId(HttpSession session){
        User user = (User)session.getAttribute("userInfoA");
        int userId = user.getUserId();
        //System.out.println(userId+"....................................................");
        return success(menuService.queryByUserId(userId));
    }
    
    /*
    @PostMapping("queryPage")
    public Result queryPage(@RequestBody Page<Menu> page){
        System.out.println("------------page(参数):"+page+"------------");
        return success(menuService.queryPage(page));
    }


    @GetMapping("queryById")
    public Result queryById(Integer menuId){
        return success(menuService.queryById(menuId));
    }
*/
    /**
     * 添加
     * @param treeNode
     * @return
     */
    @PostMapping("add")
    public Result add(@RequestBody TreeNode treeNode){
        return success(menuService.add(treeNode));
    }


    /**
     * 更新
     * @param treeNode
     * @return
     */
    @PostMapping("update")
    public Result update(@RequestBody TreeNode treeNode){
        /*System.out.println("--------------接受菜单信息为:"+treeNode);*/
        return success(menuService.update(treeNode));
    }

    /**
     * 根据Id删除
     * @param id
     * @return
     */
    @DeleteMapping("deleteById")
    public Result deleteById(Integer id){//普通属性传参，不需要加@RequestBody
        /*System.out.println("------------删除id为："+id);*/
        return success(menuService.deleteById(id));
    }

}
